#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define y1 y_alpha_1

using namespace std;

using ll = long long;
using db = double;
using vec = vector<int>;
using pii = pair<int,int>;

int read() {
	int x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-',ch = getchar();
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48),ch = getchar();
	return f ? -x : x;
}

const int N = 5e4 + 10;
const int M = 1e5 + 10;

int n,m,Q,cnt;
int ans[M],lst[M];
struct bri { int u,v,w,id; } e[M],e1[M],e2[M << 1];
bool vis[M];
struct modify { int s,w,id; };
vector < modify > cag,qry;

namespace D {
	int siz[N],fa[N];
	int modi[N][2],top;
	void reset() { for(int i = 1;i <= n;i++) siz[i] = 1,fa[i] = i; top = 0; }
	int gf(int x) { return fa[x] == x ? x : gf(fa[x]); } 
	void merge(int x,int y,int tp = 0) {
		x = gf(x),y = gf(y); if(x == y) return; if(siz[x] > siz[y]) swap(x,y); if(tp) modi[++top][0] = x,modi[top][1] = y;
		fa[x] = y; siz[y] += siz[x]; 
	}
	void undo() {
		while(top) {
			int x = modi[top][0],y = modi[top][1];
			fa[x] = x; siz[y] -= siz[x];
			top--;
		}
	}
}

void solve() {
	D :: reset(); for(int i = 1;i <= m;i++) vis[i] = 0;
	int pos = 1,top1 = 0;
	for(auto d : cag) vis[d.s] = 1;
	for(int i = 1;i <= m;i++) if(!vis[i]) e1[++top1] = e[i];
	sort(e1 + 1,e1 + top1 + 1,[](bri a,bri b) { return a.w > b.w; });
	sort(qry.begin(),qry.end(),[](modify a,modify b) { return a.w > b.w; });
	for(auto q : qry) {
		while(pos <= top1 && e1[pos].w >= q.w) D :: merge(e1[pos].u,e1[pos].v),pos++;
		int top2 = 0;
		for(auto d : cag) if(d.id < q.id) lst[d.s] = e[d.s].w;
		for(auto d : cag) if(d.id < q.id) e[d.s].w = d.w; else break;
		for(auto d : cag) e2[++top2] = e[d.s];
		for(int i = 1;i <= top2;i++) 
			if(e2[i].w >= q.w) D :: merge(e2[i].u,e2[i].v,1);
		for(auto d : cag) if(d.id < q.id) e[d.s].w = lst[d.s];
		ans[q.id] = D :: siz[D :: gf(q.s)];
		D :: undo();
	}
	for(auto d : cag) e[d.s].w = d.w;
	qry.clear(); cag.clear();
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,m = in;
	for(int i = 1;i <= m;i++) e[i].u = in,e[i].v = in,e[i].w = in,e[i].id = i;
	Q = in; int cnt = 0,lim = sqrt(m * log2(n));
	for(int i = 1;i <= Q;i++) {
		int op = in,s = in,w = in;
		if(op == 1) cag.pb((modify) { s , w , i } );
		else qry.pb((modify) { s , w , i });
		cnt++; if(cnt == lim) solve(),cnt = 0;
	}
	if(cnt) solve();
	for(int i = 1;i <= Q;i++) if(ans[i]) printf("%d\n",ans[i]);
	return 0;
}
